import React, { Component } from 'react'
import { observable, action } from 'mobx'
import * as shop from '../api/shop'

export default class productsStore {
  @observable all = []
  @observable foo = 'bar'

  constructor (rootStore) {
    this.rootStore = rootStore
  }

  @action.bound getAllProducts () {
    shop.getAllProducts().then(products => {
      // console.log(products)
      // debugger
      this.setProducts(products)
    })
  }

  @action.bound setProducts (products) {
    this.all = products
  }

  // 减少库存
  @action.bound decrementInventory (product) {
    const prod = this.all.find(item => item.id === product.id)
    prod.inventory--
  }


}
